package com.substation.ui.dialog;

import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.substation.R;
import com.substation.utils.DensityUtils;
import com.substation.utils.ScreenUtils;


/**
 * 中部dialog
 */
public abstract class BaseCenterFragmentDialog extends DialogFragment {

    protected View v;
    protected LayoutInflater inflater;
    protected Context context;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.inflater = inflater;
        context = getActivity();
        initViews();
        return v;
    }

    @Override
    public void onResume() {
        getDialog().getWindow().setLayout(ScreenUtils.getScreenWidth(getActivity()) - DensityUtils.dp2px(getActivity(), 50),
                getDialog().getWindow().getAttributes().height);//设置小于屏幕宽度50dp
        getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        super.onResume();
    }

    @Override
    public void onStart() {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height);
        getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }

    protected abstract void initViews();
}
